home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Commun⁄Network / NewsWatcher 2.0d17 Source / source / init.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-01  |  4.2 KB  |  182 lines  |  [TEXT/KAHL]

  1. /*----------------------------------------------------------------------------
  2.  
  3.     init.c
  4.  
  5.     This module handles initialization of the program.
  6.     
  7.     Portions copyright © 1990, Apple Computer.
  8.     Portions copyright © 1993, Northwestern University.
  9.  
  10. ----------------------------------------------------------------------------*/
  11.  
  12. #include <GestaltEqu.h>
  13. #include <Traps.h>
  14. #include <stdio.h>
  15. #include <string.h>
  16.  
  17. #include "glob.h"
  18. #include "init.h"
  19. #include "menus.h"
  20. #include "util.h"
  21. #include "dlgutil.h"
  22. #include "aevt.h"
  23. #include "prefs.h"
  24. #include "nntp.h"
  25. #include "full.h"
  26. #include "newsrc.h"
  27. #include "killfile.h"
  28. #include "log.h"
  29.  
  30.  
  31.  
  32. /*----------------------------------------------------------------------------
  33.     SetUpMenus 
  34.     
  35.     Draws the pull-down menus onto the screen.     
  36. ----------------------------------------------------------------------------*/
  37.  
  38. static void SetUpMenus (void)
  39. {
  40.     Handle mbar;
  41.     
  42.     mbar = GetNewMBar(kMBarID);
  43.     SetMenuBar(mbar);
  44.     AddResMenu(GetMHandle(kAppleMenu), 'DRVR');
  45.     
  46.     #ifndef FILTERS
  47.     {
  48.         short item;
  49.         MenuHandle theMenu;
  50.         Str255 theCommand;
  51.         
  52.         theMenu = GetMHandle(kSearchMenu);
  53.         for (item = kGroupKillItem; item <= kKillSubjectItem; item++) {
  54.             GetItem(theMenu, item, theCommand);
  55.             BlockMove(theCommand+1, theCommand+2, *theCommand+1);
  56.             theCommand[1] = '¬';
  57.             (*theCommand)++;
  58.             SetItem(theMenu, item, theCommand);
  59.         }
  60.     }
  61.     #endif
  62.     
  63.     DrawMenuBar();
  64. }
  65.  
  66.  
  67.  
  68. /*----------------------------------------------------------------------------
  69.     Init 
  70.         
  71.     Initializes the program.     
  72. ----------------------------------------------------------------------------*/
  73.  
  74. void Init (void)
  75. {
  76.     EventRecord ev;
  77.     CStr255 msg;
  78.     Boolean mightHaveNewGroups = true;
  79.     short sizeofTPrefRec;
  80.     FSSpec **docList = nil;
  81.     short numDocs;
  82.     long systemVersion;
  83.     long quickdrawVersion;
  84.     OSErr err;
  85.     
  86.     extern Boolean TrapAvailable (unsigned long theTrap);    /* defined in dnr.c! */
  87.     
  88.     gLifeBoat = NewHandle(kLifeBoatSize);
  89.     if (MemError() == noErr)
  90.         gSinking = false;
  91.     MoveHHi(gLifeBoat);
  92.     HLock(gLifeBoat);
  93.     
  94.     InitGraf(&qd.thePort);
  95.     InitFonts();
  96.     InitWindows();
  97.     InitMenus();
  98.     TEInit();
  99.     InitDialogs(nil);
  100.     InitCursor();
  101.     InitCursorCtl(nil);
  102.  
  103.     FlushEvents(everyEvent,0);
  104.     EventAvail(everyEvent,&ev);
  105.  
  106.     if (!TrapAvailable(_Gestalt)) {
  107.         ErrorMessage("NewsWatcher requires System 7.0 or later.");
  108.         ExitToShell();
  109.     }
  110.     err = Gestalt(gestaltSystemVersion, &systemVersion);
  111.     if (err != noErr || systemVersion < 0x0700) {
  112.         ErrorMessage("NewsWatcher requires System 7.0 or later.");
  113.         ExitToShell();
  114.     }
  115.     
  116.     err = Gestalt(gestaltQuickdrawVersion, &quickdrawVersion);
  117.     gHasColorQD = err == noErr && quickdrawVersion >= gestalt8BitQD;
  118.  
  119.     gDesktopExtent = (**GetGrayRgn()).rgnBBox;
  120.     gDragRect = gDesktopExtent;
  121.     InsetRect(&gDragRect,4,4);
  122.     SetRect(&gWindLimits,kMinWindWidth,kMinWindHeight,6000,6000);
  123.     gIBeamCurs = **(GetCursor(iBeamCursor));
  124.     SpinCursor(0);
  125.     
  126.     sizeofTPrefRec = sizeof(TPrefRec);
  127.     if (sizeofTPrefRec != kTPrefRecSize) {
  128.         sprintf(msg, "sizeof(TPrefRec) is %d, should be %d", sizeofTPrefRec,
  129.             kTPrefRecSize);
  130.         ErrorMessage(msg);
  131.         ExitToShell();
  132.     }
  133.  
  134.     SetUpMenus();
  135.     
  136. /*ErrorMessage("NewsWatcher 2.0d16 special test version for Stephan Somogyi! Please do not redistribute!");*/
  137.  
  138.     InitializeAppleEvents();
  139.     GetInitialDocList(&docList, &numDocs);
  140.     LocatePrefsFile(docList, numDocs);
  141.     FSMakeFSSpec(gPrefsFile.vRefNum, gPrefsFile.parID, kFilterName, &gFilterFile);
  142.     gStartupOK = ReadPrefs();
  143.     if (gPrefs.logActionsToFile) OpenLogFile();
  144.  
  145.     #ifdef FILTERS
  146.         if (gStartupOK) gStartupOK = ReadKillFile();
  147.     #endif
  148.  
  149.     if (gStartupOK) gStartupOK = StartNNTP();
  150.     
  151.     if (gStartupOK && gNumGroups == 0) {
  152.         gStartupOK = ReadGroupsFromServer();
  153.         mightHaveNewGroups = false;
  154.     }
  155.     
  156.     if (gStartupOK) gStartupOK = CreateFullGroupListWindow();
  157.     
  158.     if (gStartupOK && mightHaveNewGroups && gPrefs.checkForNewGroups)
  159.         CheckForNewGroups();
  160.  
  161.     if (gStartupOK) {
  162.         if (gPrefs.autoFetchnewsrc) {
  163.             DoGetGroupListFromHost(true);
  164.             gCancel = false;
  165.         }
  166.         OpenDocList(docList, numDocs);
  167.     }
  168.     
  169.     if (gStartupOK) CreateNewGroupListWindow();
  170.     
  171.     if (!gStartupOK) {
  172.         EndNNTP();
  173.         strcpy(msg, "An error occurred during the startup process, ");
  174.         strcat(msg, "or you canceled the startup process. ");
  175.         strcat(msg, "You may adjust NewsWatcher’s preferences, ");
  176.         strcat(msg, "but you will not be able to read or post news.");
  177.         ErrorMessage(msg);
  178.     }
  179.     
  180.     gStartingUp = false;
  181. }
  182.